﻿@using DTcms.Common;
@{
    ViewBag.Title = "站内短消息";
    List<SelectListItem> selectList = new List<SelectListItem>() {
        new SelectListItem(){ Text="全部类型...", Value="0"},
        new SelectListItem(){ Text="系统消息", Value="1"},
        new SelectListItem(){ Text="收件箱", Value="2"},
        new SelectListItem(){ Text="发件箱", Value="3"}
    };
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">会员设置</a> </li>
            <li><a href="javascript:;">站内短消息</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../users/message_edit?action=@DTEnums.ActionEnum.Add"><i class="iconfont icon-close1"></i> 发送消息</a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i> 删除</a>
                        </div>
                        <div class="menu-select">
                            @Html.DropDownList("ddlType", new SelectList(selectList, "Value", "Text"), new { @lay_filter = "btnSearch" })
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'type', templet:'#typeTpl'}">类型</th>
                        <th lay-data="{field:'accept_user_name'}">收件人</th>
                        <th lay-data="{field:'title'}">标题</th>
                        <th lay-data="{field:'is_read',templet: '#is_read'}">状态</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="is_read">
    {{d.is_read==1?'已阅读':'未阅读'}}
</script>
<script type="text/html" id="barDemo">
    <a href="../users/message_edit?action=@DTEnums.ActionEnum.View&id={{d.id}}" class="layui-btn layui-btn-xs"><i class="fa fa-eye"></i> 查看</a>
</script>
<script type="text/html" id="typeTpl">
    {{#  if(d.type==1){ }}
    <span>系统消息</span>
    {{#  } else if(d.type==2){ }}
    <span>收件箱</span>
    {{#  }else if(d.type==3){ }}
    <span>发件箱</span>
    {{#  } }}
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table', 'cmswh'], function () {
            var table = layui.table, form = layui.form, cmswh = layui.cmswh, $ = layui.jquery;

            cmswh.dataBind('MessageList');
            form.on('select(btnSearch)', function (data) {
                var type = "btnSearch";
                active[type] ? active[type].call(this) : '';
            });
            var active = {
                btnDelete: function () {
                    cmswh.batOperate('MessageDelete', 'id');
                },
                btnSearch: function () {
                    table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                }
            };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var typeId = $("#ddlType").val();
                var postdata = { keywords: keywords, type_id: typeId };
                return postdata;
            }
        });
    </script>
}
